import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { globalConfig, $fn, $http, $Lazy } = window
const { COVIDUrl } = globalConfig
// ===================================================================== 
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data: [],
		// 客户变更
		formData:[
			{ label: '医院名称', 		name:'new_hosp_id', 	full:true, 		type:'select',		required:true,	idStr:'uuid',	nameStr:'hospName'},
		]
	}
	submit = {}
	
	componentDidMount(){
		this.getSelect()
	}
	open = (uuid)=> {
		this.submit.uuid = uuid
		this.modal.open({formRef: this.formRef})
	}
	
	getSelect = () => {
		const { formData } = this.state
		
		$cache.then( async f => {
			// 医院
			this.hostData = await f.getCache({ api:COVIDUrl+'Hospital/query',param:{page:1,page_num:10000,status:1} })
			$fn.setRow( formData, 'new_hosp_id',  this.hostData)
			//
			this.setState({ formData })
		})
	}
	
	render(){
		return FormModal.call(this,{ title:'修改医院', labelWidth:'s5', width:800,enter:false,
			onSubmit:() => {
				const { new_hosp_id } = this.formRef.getValue()
				$http.submit(this,COVIDUrl+'caseinfo/chhosp',{ param:{uuid:this.submit.uuid, new_hosp_id}}).then(data=>{
					this.modal.close()
					this.props.onRefresh()
				})
			}
		})
	}
}

export default Index